package com.qf.juc.demo;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class CallableDemo {

    public static void main(String[] args) {

        MyThread thread =  new MyThread(); // callable接口实现类

        FutureTask futureTask = new FutureTask(thread);

        new Thread(futureTask,"A").start();
        new Thread(futureTask,"B").start();//只执行了一次call方法，有缓存
        new Thread(new FutureTask(new MyThread())).start();

    }

}


class MyThread implements Callable<String>{

    @Override
    public String call() throws Exception {
        System.err.println("call方法执行了");
        return "123456";
    }
}
